package com.crr.controller;

import cn.hutool.core.bean.BeanUtil;
import com.crr.bean.ProductHistory;
import com.crr.common.bean.PageBean;
import com.crr.common.bean.ResultBean;
import com.crr.common.controller.BaseController;
import com.crr.query.ProductCustomerQuery;
import com.crr.query.ProductQuery;
import com.crr.service.ProductHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "浏览记录")
@RestController
@RequestMapping("/v1")
public class ProductHistoryController extends BaseController {
    @Autowired
    ProductHistoryService productHistoryService;

    @ApiOperation("浏览记录列表")
    @PostMapping("/history/query")
    public ResultBean query(@RequestBody ProductCustomerQuery productCustomerQuery){
        PageBean bean = productHistoryService.query(BeanUtil.beanToMap(productCustomerQuery));
        return  success("浏览记录列表",bean);
    }
    @PutMapping("/history")
    @ApiOperation("修改查看次数")
    public ResultBean update(@RequestBody ProductHistory productHistory){
        int res = productHistoryService.update(productHistory);
        return updateResult(res);
    }
}
